package net.jxtz.jxtzos.authentication.weixin;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors;

/**
 *
 * 自定义微信UserDetails，spring security 的 user类
 *
 * @author a123
 */

@Data
@NoArgsConstructor
public class WechatUserDetails implements Serializable, UserDetails {

    /**
     * 用户id
     */
    private Long id;

    private String userName;

    /**
     * union id 当作密码
     */
    private String unionId;

    private Set<? extends GrantedAuthority> authorities;

    public WechatUserDetails(Long id, String userName, String unionId, Set<? extends GrantedAuthority> authorities){
        this.id = id;
        this.userName = userName;
        this.unionId = unionId;
        this.authorities = authorities;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return unionId;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
